<?php
/**
 * created by zzy
 * date: 2018/1/26 14:04
 */
namespace App\Eloquent\Ygt;

class WarehouseCart extends DbEloquent{

    protected $table    = 'ygt_warehouse_cart';
    public static $tableFieldList   = [
        ['name'=>'id','title'=>'','value'=>0,'is_must'=>0],
        ['name'=>'company_id','title'=>'登录用户异常','value'=>0,'is_must'=>1],
        ['name'=>'user_id','title'=>'登录用户异常','value'=>0,'is_must'=>1],
        ['name'=>'warehouse_id','title'=>'入库单','value'=>0,'is_must'=>1],
        ['name'=>'customer_id','title'=>'客户','value'=>0,'is_must'=>1],
        ['name'=>'order_id','title'=>'工单','value'=>0,'is_must'=>1],
        ['name'=>'number','title'=>'数量','value'=>0,'is_must'=>1],
    ];
    public static function edit($data,$pk='')
    {
        $id                 = isset($data['id']) ? intval($data['id']) : 0;
        if($id>0){
            $where          = ['id'=>$id];
            $result         = self::updateOneData($where,$data,$pk);
        } else {
            $result         = self::insertOneData($data,$pk);
        }
        return $result;
    }
    //取对应客户的购物车列表
    public static function getListByCustomerId($customerId)
    {
        $column             = 'id,warehouse_id,order_id,number,created_at';
        $where              = ['warehouse_bill_id'=>0,'customer_id'=>$customerId];
        $lists              = self::getList($where,$column)->toArray();
        foreach($lists as $key=>$val)
        {
            $lists[$key]['created_at']  = date('Y-m-d',$val['created_at']);
        }
        return $lists;
    }
}
